<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2019 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\plugins\orderexportprint;

use think\Controller;
use app\service\PluginsService;
use app\plugins\orderexportprint\service\BaseService;

/**
 * 订单导出打印 - 钩子入口
 * @author   Devil
 * @blog     http://gong.gg/
 * @version  0.0.1
 * @datetime 2019-08-11T21:51:08+0800
 */
class Hook extends Controller
{
    /**
     * 应用响应入口
     * @author   Devil
     * @blog     http://gong.gg/
     * @version  1.0.0
     * @datetime 2019-08-11T14:25:44+0800
     * @param    [array]          $params [输入参数]
     */
    public function run($params = [])
    {
        // 钩子名称
        $ret = '';
        if(!empty($params['hook_name']))
        {
            $config = BaseService::BaseConfig();
            switch($params['hook_name'])
            {
                // 导出按钮
                case 'plugins_view_admin_order_top_operate' :
                    $ret = $this->AdminOrderViewTopHtml($config['data'], $params);
                    break;

                // 打印按钮
                case 'plugins_view_admin_order_list_operate' :
                    $ret = $this->AdminOrderViewListHtml($config['data'], $params);
                    break;
            }
        }
        return $ret;
    }

    /**
     * 导出按钮
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-02-13
     * @desc    description
     * @param   [array]           $config [插件配置]
     * @param   [array]           $params [输入参数]
     */
    private function AdminOrderViewTopHtml($config, $params = [])
    {
        if(isset($config['is_export']) && $config['is_export'] == 1)
        {
            $url = PluginsAdminUrl('orderexportprint', 'export', 'index', input());
            $this->assign('export_url', $url);
            return $this->fetch('../../../plugins/view/orderexportprint/admin/public/top');
        }
    }

    /**
     * 打印按钮
     * @author  Devil
     * @blog    http://gong.gg/
     * @version 1.0.0
     * @date    2020-02-13
     * @desc    description
     * @param   [array]           $config [插件配置]
     * @param   [array]           $params [输入参数]
     */
    private function AdminOrderViewListHtml($config, $params = [])
    {

        if(isset($config['is_print']) && $config['is_print'] == 1)
        {
            if(empty($config['print_order_status_ids_all']) || in_array($params['data']['status'], $config['print_order_status_ids_all']))
            {
                $url = PluginsAdminUrl('orderexportprint', 'printing', 'index', ['id'=>$params['id']]);
                $this->assign('print_url', $url);
                return $this->fetch('../../../plugins/view/orderexportprint/admin/public/list');
            }
        }
    }
}
?>